package ascii

import (
	"fmt"
	"os"
	"strings"
)

//将一个文件夹里的图片, 全部转成字符图片
func BatchTransAscii(picDirectory string, asciiDirectory string) {
	//1. 先清空输出文件夹
	os.RemoveAll(asciiDirectory)
	//2. 创建输出文件夹
	os.MkdirAll(asciiDirectory, 0777)
	//3. 读取图片文件夹
	dirEntries, _ := os.ReadDir(picDirectory)
	for _, entry := range dirEntries {
		if entry.IsDir() { //不管文件夹
			continue
		}
		filename := entry.Name()
		//4. 图片转换成ascii图案
		asciiPic := Pic2Ascii(picDirectory + "\\" + filename)
		//5. 写入ascii文件
		txtFilePath := fmt.Sprintf("%s\\%s.txt", asciiDirectory, filename[0:strings.LastIndex(filename, ".")])
		os.WriteFile(txtFilePath, []byte(asciiPic), 0666)
	}
}
